package com.tyt.lelan.adapter;

import java.util.ArrayList;

import com.tyt.lelan.R;
import com.tyt.lelan.entity.RssItem;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;

public class RssItemAdapter  extends BaseAdapter{

	private Context mContext;
	private ArrayList<RssItem> mList;
	private int page;
	private final int PAGE_SIZE_RSSLIST=8;
	
	public RssItemAdapter(Context context,ArrayList<RssItem> data,int page){
		
		this.mContext=context;
		this.mList=data;
		this.page=page;
		
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		int i = page * PAGE_SIZE_RSSLIST;
		int iEnd = i+PAGE_SIZE_RSSLIST;
		int size=mList.size();
		if(size>i&&size<iEnd)
			return (size-i);
		else
			return PAGE_SIZE_RSSLIST;
		
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(page*PAGE_SIZE_RSSLIST+position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ItemViewHolder holder = new ItemViewHolder();
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_rssitem, null);
			holder.textView_title=(TextView)convertView.findViewById(R.id.tv_rssitem_title);
			holder.textView_time=(TextView)convertView.findViewById(R.id.tv_rssitem_time);
			convertView.setTag(holder);
		} else{
			holder = (ItemViewHolder)convertView.getTag();
		}
		
		RssItem temp=mList.get(position);
		holder.textView_time.setText(temp.getTime());
		holder.textView_title.setText(temp.getTitle());
		
		return convertView;
	}

	protected class ItemViewHolder {
		private TextView textView_time;
		private TextView textView_title;
	}

}
